package ihm;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;

import metier.Velo;
import dao.DAO_Client;
import dao.DAO_Employe;
import dao.DAO_Reservation;
import dao.DAO_TypeVelo;
import dao.DAO_Velo;

public class FenetrePrincipal extends JFrame implements ActionListener
{
	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenu mnFichier;
	private JMenu mnGestionEmployes;
	private JMenu mnGestionVelos;
	private JMenuItem mntmQuitter;
	private JMenuItem mntmAjouteEmploye;
	private JMenuItem mntmModifierEmploye;
	private JMenuItem mntmSupprimerEmploye;
	private JMenuItem mntmAjouterVelo;
	private JMenuItem mntmModifierVelo;
	private JMenuItem mntmSupprimerVelo;
	private JSeparator separator;
	private JMenu mnGestionClients;
	private JMenuItem mntmAjouterClient;
	private JMenuItem mntmModifierClient;
	private JMenuItem mntmSupprimerClient;
	private JMenuItem mntmVoirClients;
	private JMenuItem mntmVoirEmploye;
	private JMenuItem mntmVoirVelo;
	private JSeparator separator_1;
	private JSeparator separator_2;
	private JSeparator separator_3;
	private JMenu mnGestionLocations;
	private JMenuItem mntmVoirLocations;
	private JMenuItem mntmAccueil;
	private Vector<Velo> lesVelos;
	private JMenuItem mntmRservation;
	private JSeparator separator_4;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					FenetrePrincipal frame = new FenetrePrincipal();
					frame.setVisible(true);
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FenetrePrincipal()
	{
		setTitle("SIO - Location");
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 730, 460);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		mnFichier = new JMenu("Fichier");
		mnFichier.setIcon(new ImageIcon(FenetrePrincipal.class.getResource("/images/glyphicons_020_home.png")));
		menuBar.add(mnFichier);
		
		mntmAccueil = new JMenuItem("Accueil");
		mntmAccueil.addActionListener(this);
		mnFichier.add(mntmAccueil);
		
		mntmQuitter = new JMenuItem("Quitter");
		mntmQuitter.addActionListener(this);
		
		separator = new JSeparator();
		mnFichier.add(separator);
		mnFichier.add(mntmQuitter);
		
		mnGestionClients = new JMenu("Gestion Clients");
		mnGestionClients.setIcon(new ImageIcon(FenetrePrincipal.class.getResource("/images/glyphicons_024_parents.png")));
		menuBar.add(mnGestionClients);
		
		mntmAjouterClient = new JMenuItem("Ajouter");	
		mntmAjouterClient.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		mntmAjouterClient.addActionListener(this);
		mnGestionClients.add(mntmAjouterClient);
		
		mntmModifierClient = new JMenuItem("Modifier");
		mntmModifierClient.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		mntmModifierClient.addActionListener(this);
		mnGestionClients.add(mntmModifierClient);
		
		mntmSupprimerClient = new JMenuItem("Supprimer");
		mntmSupprimerClient.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
		mntmSupprimerClient.addActionListener(this);
		mnGestionClients.add(mntmSupprimerClient);
		
		separator_3 = new JSeparator();
		mnGestionClients.add(separator_3);
		
		mntmVoirClients = new JMenuItem("Voir Clients");
		mntmVoirClients.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
		mntmVoirClients.addActionListener(this);
		mnGestionClients.add(mntmVoirClients);
		
		mnGestionEmployes = new JMenu("Gestion Employes");
		mnGestionEmployes.setIcon(new ImageIcon(FenetrePrincipal.class.getResource("/images/glyphicons_043_group.png")));
		menuBar.add(mnGestionEmployes);
		
		mntmAjouteEmploye = new JMenuItem("Ajouter");
		mntmAjouteEmploye.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
		mntmAjouteEmploye.addActionListener(this);
		mnGestionEmployes.add(mntmAjouteEmploye);
		
		
		mntmModifierEmploye = new JMenuItem("Modifier");
		mntmModifierEmploye.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		mntmModifierEmploye.addActionListener(this);
		mnGestionEmployes.add(mntmModifierEmploye);
		
		mntmSupprimerEmploye = new JMenuItem("Supprimer");
		mntmSupprimerEmploye.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		mntmSupprimerEmploye.addActionListener(this);
		mnGestionEmployes.add(mntmSupprimerEmploye);
		
		separator_2 = new JSeparator();
		mnGestionEmployes.add(separator_2);
		
		mntmVoirEmploye = new JMenuItem("Voir Employ\u00E9s");
		mntmVoirEmploye.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		mntmVoirEmploye.addActionListener(this);
		mnGestionEmployes.add(mntmVoirEmploye);
		
		mnGestionVelos = new JMenu("Gestion Velos");
		mnGestionVelos.setIcon(new ImageIcon(FenetrePrincipal.class.getResource("/images/glyphicons_306_bicycle.png")));
		menuBar.add(mnGestionVelos);
		
		mntmAjouterVelo = new JMenuItem("Ajouter");
		mntmAjouterVelo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		mntmAjouterVelo.addActionListener(this);
		mnGestionVelos.add(mntmAjouterVelo);
		
		mntmModifierVelo = new JMenuItem("Modifier");
		mntmModifierVelo.addActionListener(this);
		mnGestionVelos.add(mntmModifierVelo);
		
		mntmSupprimerVelo = new JMenuItem("Supprimer");
		mntmSupprimerVelo.addActionListener(this);
		mnGestionVelos.add(mntmSupprimerVelo);
		
		separator_1 = new JSeparator();
		mnGestionVelos.add(separator_1);
		
		mntmVoirVelo = new JMenuItem("Voir V\u00E9los");
		mntmVoirVelo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		mntmVoirVelo.addActionListener(this);
		mnGestionVelos.add(mntmVoirVelo);
		
		mnGestionLocations = new JMenu("Gestion Locations");
		mnGestionLocations.setIcon(new ImageIcon(FenetrePrincipal.class.getResource("/images/glyphicons_119_table.png")));
		menuBar.add(mnGestionLocations);
		
		mntmVoirLocations = new JMenuItem("Voir Locations");
		mntmVoirLocations.addActionListener(this);
		
		mntmRservation = new JMenuItem("R\u00E9servation");
		mntmRservation.addActionListener(this);
		mnGestionLocations.add(mntmRservation);
		
		separator_4 = new JSeparator();
		mnGestionLocations.add(separator_4);
		mnGestionLocations.add(mntmVoirLocations);
		
		FenetreAccueil f = new FenetreAccueil();
		f.setVisible(true);	
		contentPane.add(f);
		
		lesVelos = DAO_Velo.getLesVelos();
	}
	
	public void actionPerformed(ActionEvent arg0) {
		contentPane.removeAll();
		JInternalFrame f=null;
		
		if(arg0.getSource() == this.mntmAccueil)
		{
			f = new FenetreAccueil();
		}
		
		if(arg0.getSource() == this.mntmQuitter)
		{
			System.exit(0);
		}
		
		if(arg0.getSource() == this.mntmAjouterClient)
		{
			f = new FenetreAjouterClient();
		}
		
		if(arg0.getSource() == this.mntmModifierClient)
		{
			f = new FenetreModifierClient(DAO_Client.getLesClients());
		}
		
		if(arg0.getSource() == this.mntmSupprimerClient)
		{
			f = new FenetreSupprimerClient(DAO_Client.getLesClients());
		}
		
		if(arg0.getSource() == this.mntmVoirClients)
		{
			f = new FenetreVoirClient();
		}
		
		if(arg0.getSource() == this.mntmAjouteEmploye)
		{
			f = new FenetreAjoutEmploye();
		}
		
		if(arg0.getSource() == this.mntmModifierEmploye)
		{
			f = new FenetreModifierEmploye(DAO_Employe.getLesEmployes());
		}
		
		if(arg0.getSource() == this.mntmSupprimerEmploye)
		{
			f = new FenetreSupprimerEmploye(DAO_Employe.getLesEmployes());
		}
		
		if(arg0.getSource() == this.mntmVoirEmploye)
		{
			f = new FenetreVoirEmploye();
		}
		
		if(arg0.getSource() == this.mntmAjouterVelo)
		{
			f = new FenetreAjouterVelo(DAO_TypeVelo.getLesTypeVelos());
		}
		
		if(arg0.getSource() == this.mntmModifierVelo)
		{
			f = new FenetreModifierVelo(DAO_Velo.getLesVelos(), DAO_TypeVelo.getLesTypeVelos());
		}
		
		if(arg0.getSource() == this.mntmSupprimerVelo)
		{
			f = new FenetreDeleteVelo(DAO_Velo.getLesVelos());
		}
		
		if(arg0.getSource() == this.mntmVoirVelo)
		{
			f = new FenetreVoirVelo();
		}
		
		if(arg0.getSource() == this.mntmRservation)
		{
			f = new FenetreReservation(DAO_Velo.getLesVelos(), DAO_Client.getLesClients());
		}
				
		if(arg0.getSource() == this.mntmVoirLocations)
		{
			f = new FenetreVoirReservation(DAO_Reservation.getLesReservations());
		}
		
		contentPane.add(f);
		f.setVisible(true);	
	}
}
